package jm.nj.demo14mian.demo04;

import java.io.*;
import java.net.Socket;

/*
* TCP文件传输:client
* */
public class FileSocket {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("127.0.0.1",8888);

        OutputStream out = socket.getOutputStream();

        BufferedInputStream fileIn = new BufferedInputStream(new FileInputStream("D:\\123.jpg"));

        byte[] buffer = new byte[1024];
        int len = -1;
        while ((len  = fileIn.read(buffer))!=-1){
            out.write(buffer,0,len);
        }
        socket.shutdownOutput();


        //---------接收反馈----------

        InputStream in = socket.getInputStream();

        byte[] info = new byte[1024];
        int length = in.read(info);
        /*System.out.println(length);
        System.out.println(info);*/

        System.out.println(new String(info,0,length));



    }
}
